/*
 * TestNetBeans.java
 *
 * Created on November 29, 2006, 10:28 AM
 */

package gui;

import javax.swing.*;

import java.awt.*;

import javax.swing.text.*;
import java.util.regex.*;
import java.util.*;

import road.Road;
import simulation.*;
import javax.swing.tree.*;

import neighborhood.Neighborhood;

/**
 * GUI is the interface that is shown to the user. The user interacts with the
 * Simulation class through the GUI by setting the simulation's initial
 * conditions on the GUI.
 * 
 * @author Team Switchboard Boxcar
 * 
 */
public class GUI extends javax.swing.JPanel {

	private DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(
			"Simulation Statistics", true);

	private boolean settingsActive = true;

	private int[] addlLanes = new int[] { 0, 0, 0, 0, 0, 0 };

	private ArrayList<int[]> accidents[];

	private String[][] streetDirections = new String[][] {
			new String[] { "East", "West" }, new String[] { "North", "South" },
			new String[] { "Northwest", "Southeast" },
			new String[] { "North", "South" },
			new String[] { "North", "South" }, new String[] { "East", "West" } };

	private String[][] railDirections = new String[][] {
			new String[] { "East", "West" }, new String[] { "North", "South" },
			new String[] { "North", "South" }, new String[] { "East", "West" } };

	private String[] railNames = new String[] { "Rail A", "Rail B", "Rail C",
			"Rail D" };

	private int[] numLanes = new int[] { 2, 2, 3, 1, 2, 2 };

	private JTextPane[] guiRoadSettings;

	int[][] lookupStartingNeigh = new int[][] { new int[] { 0, 1 },
			new int[] { 3, 0 }, new int[] { 2, 0 }, new int[] { 2, 1 },
			new int[] { 2, 1 }, new int[] { 3, 2 } };

	int[][] lookupRoadIdxs = new int[][] { new int[] { 0, 3 },
			new int[] { 0, 3 }, new int[] { 2, 2 }, new int[] { 3, 1 },
			new int[] { 4, 0 }, new int[] { 3, 0 } };

	public static void main(String[] args) {
		// Set the look and feel.
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			// If setting the look and feel failed, schedule a log to inform the
			// user
			final String stackTrace = e.toString();
			javax.swing.SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					// log("Error: Couldn't get System look and feel. Using
					// default.\n" + stackTrace);
				}
			});
		}

		// Make sure we have nice window decorations.
		JFrame.setDefaultLookAndFeelDecorated(true);

		// Create and set up the window.
		JFrame frame = new JFrame("Switchboard Boxcar: Cars and Trains");
		// frame.add();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// GUI app = new GUI();
		// Component contents = app.createComponents();
		frame.getContentPane().add(new GUI(), BorderLayout.CENTER);
		frame.setResizable(false);

		// Display the window.
		frame.pack();
		frame.setVisible(true);
	}

	/**
	 * GUI() initializes the GUI class and displays the interface to the user.
	 */
	public GUI() {
		accidents = new ArrayList[6];
		for (int i = 0; i < accidents.length; i++)
			accidents[i] = new ArrayList<int[]>();
		initComponents();
		guiRoadSettings = new JTextPane[] { jTextPaneA, jTextPaneB, jTextPaneC,
				jTextPaneD, jTextPaneE, jTextPaneF };
		ResetGUI();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor./**
	 * 
	 * Not deprecated, hide from JavaDoc to keep it clean.
	 * @deprectated-nodeprecated
	 */
	// <editor-fold defaultstate="collapsed" desc=" Generated Code
	// ">//GEN-BEGIN:initComponents
	private void initComponents() {
		jLabel12 = new javax.swing.JLabel();
		jTextPaneA = new javax.swing.JTextPane();
		jTextPaneB = new javax.swing.JTextPane();
		jTextPaneC = new javax.swing.JTextPane();
		jTextPaneD = new javax.swing.JTextPane();
		jTextPaneE = new javax.swing.JTextPane();
		jTextPaneF = new javax.swing.JTextPane();
		jButton1 = new javax.swing.JButton();
		jButton2 = new javax.swing.JButton();
		jLabel1 = new javax.swing.JLabel();
		jTabbedPane1 = new javax.swing.JTabbedPane();
		jPanel1 = new javax.swing.JPanel();
		jPanel3 = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jList1 = new javax.swing.JList();
		jLabel3 = new javax.swing.JLabel();
		jPanel4 = new javax.swing.JPanel();
		jLabel4 = new javax.swing.JLabel();
		jComboBox1 = new javax.swing.JComboBox();
		jScrollPane2 = new javax.swing.JScrollPane();
		jList2 = new javax.swing.JList();
		jLabel5 = new javax.swing.JLabel();
		jButton3 = new javax.swing.JButton();
		jLabel2 = new javax.swing.JLabel();
		jButton4 = new javax.swing.JButton();
		jLabel10 = new javax.swing.JLabel();
		jTextField3 = new javax.swing.JTextField();
		jComboBox3 = new javax.swing.JComboBox();
		jPanel5 = new javax.swing.JPanel();
		jLabel6 = new javax.swing.JLabel();
		jTextField1 = new javax.swing.JTextField();
		jLabel7 = new javax.swing.JLabel();
		jTextField2 = new javax.swing.JTextField();
		jLabel8 = new javax.swing.JLabel();
		jLabel9 = new javax.swing.JLabel();
		jComboBox2 = new javax.swing.JComboBox();
		jLabel11 = new javax.swing.JLabel();
		jComboBox5 = new javax.swing.JComboBox();
		jPanel2 = new javax.swing.JPanel();
		jScrollPane3 = new javax.swing.JScrollPane();
		setLayout(null);

		setPreferredSize(new java.awt.Dimension(1150, 740));
		jLabel12.setFont(new java.awt.Font("Tahoma", 1, 80));
		jLabel12.setForeground(new java.awt.Color(204, 0, 0));
		jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		add(jLabel12);
		jLabel12.setBounds(30, 230, 1010, 330);

		jTextPaneA
				.setText("Road A:\n2 Lanes\n+0 Lanes\nWest Accidents: 0\nEast Accidents: 0");
		jTextPaneA.setOpaque(false);
		add(jTextPaneA);
		jTextPaneA.setBounds(200, 40, 110, 70);

		jTextPaneB
				.setText("Road B:\n2 Lanes\n+0 Lanes\nNorth Accidents: 0\nSouth Accidents: 0");
		jTextPaneB.setOpaque(false);
		add(jTextPaneB);
		jTextPaneB.setBounds(4, 216, 110, 70);

		jTextPaneC
				.setText("Road C:\n3 Lanes\n+0 Lanes\nSoutheast Accidents: 0\nNorthwest Accidents: 0");
		jTextPaneC.setOpaque(false);
		add(jTextPaneC);
		jTextPaneC.setBounds(194, 376, 140, 76);

		jTextPaneD
				.setText("Road D:\n1 Lane\n+0 Lanes\nNorth Accidents: 0\nSouth Accidents: 0");
		jTextPaneD.setOpaque(false);
		add(jTextPaneD);
		jTextPaneD.setBounds(438, 202, 110, 90);

		jTextPaneE
				.setText("Road E:\n2 Lanes\n+0 Lanes\nNorth Accidents: 0\nSouth Accidents: 0");
		jTextPaneE.setOpaque(false);
		add(jTextPaneE);
		jTextPaneE.setBounds(646, 400, 110, 80);

		jTextPaneF
				.setText("Road F:\n1 Lane\n+0 Lanes\nWest Accidents: 0\nEast Accidents: 0");
		jTextPaneF.setOpaque(false);
		add(jTextPaneF);
		jTextPaneF.setBounds(230, 660, 110, 80);

		jButton1.setIcon(new javax.swing.ImageIcon(ClassLoader
				.getSystemResource("Images/Play.png")));
		jButton1.setText("Run");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		add(jButton1);
		jButton1.setBounds(280, 10, 85, 30);

		jButton2.setIcon(new javax.swing.ImageIcon(ClassLoader
				.getSystemResource("Images/Stop.png")));
		jButton2.setText("Reset");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		add(jButton2);
		jButton2.setBounds(390, 10, 85, 30);

		jLabel1.setIcon(new javax.swing.ImageIcon(ClassLoader
				.getSystemResource("Images/Map.png")));
		add(jLabel1);
		jLabel1.setBounds(0, 40, 750, 700);

		jTabbedPane1.setMinimumSize(new java.awt.Dimension(38, 697));
		jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
			public void stateChanged(javax.swing.event.ChangeEvent evt) {
				jTabbedPane1StateChanged(evt);
			}
		});

		jPanel1.setMinimumSize(new java.awt.Dimension(0, 630));
		jPanel1.setPreferredSize(new java.awt.Dimension(0, 630));
		jPanel3.setBorder(javax.swing.BorderFactory
				.createTitledBorder("Road Settings"));
		jList1.setModel(new javax.swing.AbstractListModel() {
			String[] strings = { "  Road A", "  Road B", "  Road C",
					"  Road D", "  Road E", "  Road F" };

			public int getSize() {
				return strings.length;
			}

			public Object getElementAt(int i) {
				return strings[i];
			}
		});
		jList1
				.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
		jList1.setFixedCellWidth(50);
		jList1.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
		jList1.setSelectedIndex(0);
		jList1.setVisibleRowCount(1);
		jList1
				.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
					public void valueChanged(
							javax.swing.event.ListSelectionEvent evt) {
						jList1ValueChanged(evt);
					}
				});

		jScrollPane1.setViewportView(jList1);

		jLabel3.setText("Road to Configure");

		jPanel4.setMaximumSize(new java.awt.Dimension(200, 32767));
		jLabel4.setText("Additional Lanes Per Side");

		jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"+0 Lanes", "+1 Lane", "+2 Lanes", "+3 Lanes" }));
		jComboBox1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jComboBox1ActionPerformed(evt);
			}
		});

		jList2.setModel(new javax.swing.AbstractListModel() {
			String[] strings = { "<No Accidents>" };

			public int getSize() {
				return strings.length;
			}

			public Object getElementAt(int i) {
				return strings[i];
			}
		});
		jList2
				.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
		jScrollPane2.setViewportView(jList2);

		jLabel5.setText("Accidents on Road A");

		jButton3.setText("Add New Accident");
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		jLabel2.setText("Time:");

		jButton4.setText("Delete Selected Accident");
		jButton4.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton4ActionPerformed(evt);
			}
		});

		jLabel10.setText("Direction:");

		jTextField3.setText("0");
		jTextField3.setInputVerifier(new InputVerifier() {
			public boolean verify(JComponent input) {
				boolean isValid = true;
				JTextField inputTextField = (JTextField) input;
				String inputText = inputTextField.getText();
				if (inputText.length() != 0) {
					try {
						int inputInt = Integer.parseInt(inputText);
						if (inputInt < 0 || inputInt > 1440)
							isValid = false;
					} catch (NumberFormatException e) {
						isValid = false;
					}
				} else
					isValid = false;
				// if (!isValid)
				//
				return isValid;
			}

			public boolean shouldYieldFocus(JComponent input) {
				boolean isValid = super.shouldYieldFocus(input);
				if (!isValid)
					getToolkit().beep();
				return isValid;
			}
		});

		jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"East", "West" }));

		org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(
				jPanel4);
		jPanel4.setLayout(jPanel4Layout);
		jPanel4Layout
				.setHorizontalGroup(jPanel4Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								jPanel4Layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												jPanel4Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																jPanel4Layout
																		.createSequentialGroup()
																		.add(
																				10,
																				10,
																				10)
																		.add(
																				jComboBox1,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
														.add(jLabel4)
														.add(jLabel5)
														.add(
																jPanel4Layout
																		.createSequentialGroup()
																		.add(
																				10,
																				10,
																				10)
																		.add(
																				jPanel4Layout
																						.createParallelGroup(
																								org.jdesktop.layout.GroupLayout.TRAILING,
																								false)
																						.add(
																								org.jdesktop.layout.GroupLayout.LEADING,
																								jPanel4Layout
																										.createSequentialGroup()
																										.add(
																												jPanel4Layout
																														.createParallelGroup(
																																org.jdesktop.layout.GroupLayout.LEADING)
																														.add(
																																jLabel10)
																														.add(
																																jLabel2))
																										.addPreferredGap(
																												org.jdesktop.layout.LayoutStyle.RELATED)
																										.add(
																												jPanel4Layout
																														.createParallelGroup(
																																org.jdesktop.layout.GroupLayout.LEADING)
																														.add(
																																jTextField3,
																																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																																49,
																																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																														.add(
																																jPanel4Layout
																																		.createSequentialGroup()
																																		.add(
																																				jComboBox3,
																																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																																		.addPreferredGap(
																																				org.jdesktop.layout.LayoutStyle.RELATED,
																																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																																				Short.MAX_VALUE)
																																		.add(
																																				jButton3))))
																						.add(
																								jButton4)
																						.add(
																								jScrollPane2,
																								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																								280,
																								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
										.addContainerGap(15, Short.MAX_VALUE)));
		jPanel4Layout
				.setVerticalGroup(jPanel4Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								jPanel4Layout
										.createSequentialGroup()
										.addContainerGap()
										.add(jLabel4)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jComboBox1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(jLabel5)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jScrollPane2,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												99,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(jButton4)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.add(
												jPanel4Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(jLabel2)
														.add(
																jTextField3,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jPanel4Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(jLabel10)
														.add(
																jComboBox3,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(jButton3)).add(9,
												9, 9)));

		org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(
				jPanel3);
		jPanel3.setLayout(jPanel3Layout);
		jPanel3Layout
				.setHorizontalGroup(jPanel3Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								jPanel3Layout
										.createSequentialGroup()
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.add(
												jPanel3Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.TRAILING)
														.add(
																org.jdesktop.layout.GroupLayout.LEADING,
																jLabel3)
														.add(
																org.jdesktop.layout.GroupLayout.LEADING,
																jScrollPane1,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(
																org.jdesktop.layout.GroupLayout.LEADING,
																jPanel4,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))));
		jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel3Layout.createSequentialGroup().add(jLabel3)
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.RELATED).add(
								jScrollPane1,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.RELATED).add(
								jPanel4,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));

		jPanel5.setBorder(javax.swing.BorderFactory
				.createTitledBorder("System Settings"));
		jLabel6.setText("Number of Trains");

		jTextField1.setText("12");
		jTextField1.setInputVerifier(new InputVerifier() {
			public boolean verify(JComponent input) {
				boolean isValid = true;
				JTextField inputTextField = (JTextField) input;
				String inputText = inputTextField.getText();
				if (inputText.length() != 0) {
					try {
						int inputInt = Integer.parseInt(inputText);
						if (inputInt < 0 || inputInt > 88)
							isValid = false;
					} catch (NumberFormatException e) {
						isValid = false;
					}
				} else
					isValid = false;
				// if (!isValid)
				//
				return isValid;
			}

			public boolean shouldYieldFocus(JComponent input) {
				boolean isValid = super.shouldYieldFocus(input);
				if (!isValid)
					getToolkit().beep();
				return isValid;
			}
		});

		jLabel7.setText("Simulation Length");

		jTextField2.setText("30");
		jTextField2.setInputVerifier(new InputVerifier() {
			public boolean verify(JComponent input) {
				boolean isValid = true;
				JTextField inputTextField = (JTextField) input;
				String inputText = inputTextField.getText();
				if (inputText.length() != 0) {
					try {
						int inputInt = Integer.parseInt(inputText);
						if (inputInt < 30 || inputInt > 1440)
							isValid = false;
					} catch (NumberFormatException e) {
						isValid = false;
					}
				} else
					isValid = false;
				// if (!isValid)
				//
				return isValid;
			}

			public boolean shouldYieldFocus(JComponent input) {
				boolean isValid = super.shouldYieldFocus(input);
				if (!isValid)
					getToolkit().beep();
				return isValid;
			}
		});

		jLabel8.setText("(Minutes)");

		jLabel9.setText("Rain?");

		jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"No", "Yes", "System Determined" }));

		jLabel11.setText("Population Activity");

		jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"High", "Medium", "Low" }));

		org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(
				jPanel5);
		jPanel5.setLayout(jPanel5Layout);
		jPanel5Layout
				.setHorizontalGroup(jPanel5Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								jPanel5Layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												jPanel5Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																jPanel5Layout
																		.createSequentialGroup()
																		.add(
																				10,
																				10,
																				10)
																		.add(
																				jComboBox5,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
														.add(
																jPanel5Layout
																		.createSequentialGroup()
																		.add(
																				jPanel5Layout
																						.createParallelGroup(
																								org.jdesktop.layout.GroupLayout.TRAILING,
																								false)
																						.add(
																								org.jdesktop.layout.GroupLayout.LEADING,
																								jPanel5Layout
																										.createSequentialGroup()
																										.add(
																												10,
																												10,
																												10)
																										.add(
																												jComboBox2,
																												0,
																												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																												Short.MAX_VALUE))
																						.add(
																								org.jdesktop.layout.GroupLayout.LEADING,
																								jLabel6)
																						.add(
																								org.jdesktop.layout.GroupLayout.LEADING,
																								jLabel7)
																						.add(
																								org.jdesktop.layout.GroupLayout.LEADING,
																								jPanel5Layout
																										.createSequentialGroup()
																										.add(
																												10,
																												10,
																												10)
																										.add(
																												jTextField2))
																						.add(
																								org.jdesktop.layout.GroupLayout.LEADING,
																								jPanel5Layout
																										.createSequentialGroup()
																										.add(
																												10,
																												10,
																												10)
																										.add(
																												jTextField1)
																										.add(
																												44,
																												44,
																												44)))
																		.addPreferredGap(
																				org.jdesktop.layout.LayoutStyle.RELATED)
																		.add(
																				jLabel8))
														.add(jLabel9).add(
																jLabel11))
										.addContainerGap(139, Short.MAX_VALUE)));
		jPanel5Layout
				.setVerticalGroup(jPanel5Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								jPanel5Layout
										.createSequentialGroup()
										.add(21, 21, 21)
										.add(jLabel6)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jTextField1,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(jLabel7)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jPanel5Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(
																jTextField2,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(jLabel8))
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(jLabel9)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jComboBox2,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(jLabel11)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												jComboBox5,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(26, Short.MAX_VALUE)));

		org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout
				.setHorizontalGroup(jPanel1Layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												jPanel1Layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.TRAILING)
														.add(
																org.jdesktop.layout.GroupLayout.LEADING,
																jPanel5,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.add(
																org.jdesktop.layout.GroupLayout.LEADING,
																jPanel3,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(4, Short.MAX_VALUE)));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(
				jPanel1Layout.createSequentialGroup().addContainerGap().add(
						jPanel3,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
						org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
						org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(
								org.jdesktop.layout.LayoutStyle.RELATED).add(
								jPanel5,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(63, Short.MAX_VALUE)));
		jTabbedPane1.addTab("Settings", jPanel1);

		org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(jScrollPane3,
				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 355,
				Short.MAX_VALUE));
		jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(jScrollPane3,
				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 692,
				Short.MAX_VALUE));
		jTabbedPane1.addTab("Statistics", jPanel2);

		add(jTabbedPane1);
		jTabbedPane1.setBounds(755, 17, 360, 720);

	}// </editor-fold>//GEN-END:initComponents

	private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jTabbedPane1StateChanged
		if (settingsActive == true)
			jTabbedPane1.setSelectedIndex(0);
		else
			jTabbedPane1.setSelectedIndex(1);
	}// GEN-LAST:event_jTabbedPane1StateChanged

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton2ActionPerformed
		if (evt.getActionCommand().equals("Reset"))
			ResetGUI();
	}// GEN-LAST:event_jButton2ActionPerformed

	private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton4ActionPerformed
		if (evt.getActionCommand().equals("Delete Selected Accident"))
			if (jList2.getSelectedIndex() >= 0)
				if (accidents[jList1.getSelectedIndex()].size() > 0)
					accidents[jList1.getSelectedIndex()].remove(jList2
							.getSelectedIndex());
		showAccidents();
		// jTextPaneA.setText("Not 'No Accidents'");
		// else
		// jTextPane1.setText("Was No Accidents");
		// else
		// jTextPane1.setText("null");

	}// GEN-LAST:event_jButton4ActionPerformed

	private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jComboBox1ActionPerformed
		if (evt.getActionCommand().equals("comboBoxChanged"))
			addlLanes[jList1.getSelectedIndex()] = jComboBox1
					.getSelectedIndex();
		updateRoadSettings(jList1.getSelectedIndex());
	}// GEN-LAST:event_jComboBox1ActionPerformed

	private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {// GEN-FIRST:event_jList1ValueChanged
		jComboBox1.setSelectedIndex(addlLanes[jList1.getSelectedIndex()]);
		jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(
				streetDirections[jList1.getSelectedIndex()]));
		jLabel5.setText("Accidents  on" + (String) jList1.getSelectedValue());
		showAccidents();
	}// GEN-LAST:event_jList1ValueChanged

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton3ActionPerformed
		try {
			int inputInt = Integer.parseInt(jTextField3.getText());
			if (evt.getActionCommand().equals("Add New Accident")) {
				if (inputInt >= 0
						&& inputInt <= Integer.parseInt(jTextField2.getText()))
					accidents[jList1.getSelectedIndex()].add(new int[] {
							Integer.parseInt(jTextField3.getText()),
							jComboBox3.getSelectedIndex() });
				else
					JOptionPane
							.showMessageDialog(this,
									"Accident time should be an integer between 0 and simulation length.");
			}
		} catch (Exception ex) {
			JOptionPane
					.showMessageDialog(this,
							"Accident time should be an integer between 0 and simulation length.");
		}
		showAccidents();
	}// GEN-LAST:event_jButton3ActionPerformed

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
		if (evt.getActionCommand().equals("Run")) {
			setEnabled(this, false);
			jLabel12.setEnabled(true);
			jLabel12.setText("Running. Please Wait...");
			// this.paint
			Play();
			setEnabled(this, true);
			jLabel12.setText("");
		}
	}// GEN-LAST:event_jButton1ActionPerformed

	/**
	 * showAccidents displays the number of accidents that are scheduled on the map.<p>This function does not take any parameters and does not return a value. The results are displayed on the GUI.
	 * 
	 * @param neighIdx
	 *            The index of the neighborhood
	 * @return roadMults
	 * 			  Multipliers for the roads in the neighborhood of index neighIdx
	 */
	private void showAccidents() {
		int currentRoad = jList1.getSelectedIndex();
		int numAccidents = accidents[currentRoad].size();
		final String[] listOfAccidents;
		if (numAccidents > 0) {
			listOfAccidents = new String[numAccidents];
			for (int j = 0; j < listOfAccidents.length; j++)
				listOfAccidents[j] = "Time: "
						+ Integer.toString(accidents[currentRoad].get(j)[0])
						+ "  Direction: "
						+ streetDirections[currentRoad][accidents[currentRoad]
								.get(j)[1]];
		} else
			listOfAccidents = new String[] { "<No  Accidents  on"
					+ (String) jList1.getSelectedValue() + ">" };
		jList2.setModel(new javax.swing.AbstractListModel() {
			public int getSize() {
				return listOfAccidents.length;
			}

			public Object getElementAt(int i) {
				return listOfAccidents[i];
			}
		});
		updateRoadSettings(currentRoad);
	}

	/**
	 * updateRoadSettings takes a road index and shows the road's settings on the GUI.
	 * 
	 * @param roadIdx
	 *            The index of road whose settings should be displayed
	 */
	private void updateRoadSettings(int roadIdx) {
		int accidents0 = 0;
		int accidents1 = 0;
		// String accidents0 = ;
		// String accidents0 = streetDirections[roadIdx][1] + " Accidents:";

		for (int i = 0; i < accidents[roadIdx].size(); i++)
			if (accidents[roadIdx].get(i)[1] == 0)
				accidents0++;
			else
				accidents1++;
		int previousSelected = jList1.getSelectedIndex();
		jList1.setSelectedIndex(roadIdx);
		guiRoadSettings[roadIdx].setText(((String) jList1.getSelectedValue())
				.trim()
				+ ":\r"
				+ Integer.toString(numLanes[roadIdx])
				+ " Lanes\r"
				+ (String) jComboBox1.getSelectedItem()
				+ "\r"
				+ streetDirections[roadIdx][0]
				+ " Accidents: "
				+ Integer.toString(accidents0)
				+ "\r"
				+ streetDirections[roadIdx][1]
				+ " Accidents: "
				+ Integer.toString(accidents1));
		jList1.setSelectedIndex(previousSelected);
	}

	private void setEnabled(Component c, boolean enabled) {
		c.setEnabled(enabled);
		try {
			Container cont = (Container) c;
			Component[] components = cont.getComponents();
			for (int i = 0; i < components.length; i++)
				setEnabled(components[i], enabled);
		} catch (Exception E) {
		}
	}

	private Simulation mainSimulation;

	/**
	 * Play runs the simulation with the settings from the GUI.<p>Nothing is taken as a parameter or returned, all the results are displayed on the GUI.
	 * 
	 */
	private void Play() {

		if (verifyInputValues()) {

			mainSimulation = new Simulation(Integer.parseInt(jTextField2
					.getText()), new int[] { 5, 5, 5, 5 }, new int[][] {
					new int[] { 65, 0, 65, 65, 0 },
					new int[] { 65, 65, 0, 65, 0 },
					new int[] { 65, 0, 65, 65, 65 },
					new int[] { 65, 0, 0, 65, 0 } }, new int[][] {
					new int[] { 2, 0, 3, 2, 0 }, new int[] { 2, 1, 0, 2, 0 },
					new int[] { 2, 0, 3, 1, 2 }, new int[] { 2, 0, 0, 2, 0 } },
					new int[][] { new int[] { 10, 0, 30, 20, 0 },
							new int[] { 20, 20, 0, 10, 0 },
							new int[] { 10, 0, 30, 20, 20 },
							new int[] { 20, 0, 0, 10, 0 } }, new double[][] {
							getRoadMultipliers(0), getRoadMultipliers(1),
							getRoadMultipliers(2), getRoadMultipliers(3) },
					new int[][] { new int[] { 1, 0, 2, 3, 0 },
							new int[] { 2, 2, 0, 0, 0 },
							new int[] { 3, 0, 0, 1, 1 },
							new int[] { 0, 0, 0, 2, 0 } });

			int numAccidents = accidents[0].size() + accidents[1].size()
					+ accidents[2].size() + accidents[3].size()
					+ accidents[4].size() + accidents[5].size();
			int[] startNeigh = new int[numAccidents];
			int[] roadIdxs = new int[numAccidents];
			int[] accidentTimes = new int[numAccidents];

			ArrayList<int[]> newAccidents[] = new ArrayList[6];
			for (int i = 0; i < newAccidents.length; i++)
				newAccidents[i] = new ArrayList<int[]>();

			for (int currentAccidentIndex = 0; currentAccidentIndex < numAccidents; currentAccidentIndex++) {
				int currentRoadIndex = 0;
				if (accidents[0].size() > 0) {
					currentRoadIndex = 0;
				} else if (accidents[1].size() > 0) {
					currentRoadIndex = 1;
				} else if (accidents[2].size() > 0) {
					currentRoadIndex = 2;
				} else if (accidents[3].size() > 0) {
					currentRoadIndex = 3;
				} else if (accidents[4].size() > 0) {
					currentRoadIndex = 4;
				} else if (accidents[5].size() > 0) {
					currentRoadIndex = 5;
				}
				startNeigh[currentAccidentIndex] = lookupStartingNeigh[currentRoadIndex][accidents[currentRoadIndex]
						.get(0)[1]];
				roadIdxs[currentAccidentIndex] = lookupRoadIdxs[currentRoadIndex][accidents[currentRoadIndex]
						.get(0)[1]];
				accidentTimes[currentAccidentIndex] = accidents[currentRoadIndex]
						.get(0)[0];
				newAccidents[currentRoadIndex].add(accidents[currentRoadIndex]
						.get(0));
				accidents[currentRoadIndex].remove(0);
			}

			accidents = newAccidents;

			mainSimulation.SetInitialConditions(getRainProb(),
					getTrafficLevel(), Integer.parseInt(jTextField1.getText()),
					numAccidents, startNeigh, roadIdxs, accidentTimes);
			mainSimulation.ProcessEvents();
			GetStatistics();
		}
	}

	private boolean verifyInputValues() {
		try {
			try {
				int numTrains = Integer.parseInt(jTextField1.getText());
				if (numTrains > 88 || numTrains < 0) {
					JOptionPane
							.showMessageDialog(this,
									"Number of trains should be an integer between 0 and 88.");
					return false;
				}
			} catch (Exception ex) {
				JOptionPane
						.showMessageDialog(this,
								"Number of trains should an integer be between 0 and 88.");
				return false;
			}
			int simLength = 0;
			try {
				simLength = Integer.parseInt(jTextField2.getText());
				if (simLength > 1440 || simLength < 30) {
					JOptionPane
							.showMessageDialog(this,
									"Simulation length should be an integer between 30 and 1440.");
					return false;
				}
			} catch (Exception ex) {
				JOptionPane
						.showMessageDialog(this,
								"Simulation length should be an integer between 30 and 1440.");
				return false;
			}

			for (int i = 0; i < accidents.length; i++)
				for (int j = 0; j < accidents[i].size(); j++) {
					if (accidents[i].get(j)[0] > simLength) {
						JOptionPane
								.showMessageDialog(
										this,
										"All accidents should occur before the end of the simulation.\r\rDelete any accidents which occur after time "
												+ jTextField2.getText());
						return false;
					}
				}
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(this,
					"An error was found in the input data.");
			return false;
		}
		return true;
	}

	
	/**
	 * getRainProb gets the selected rain probability and converts it to a double value
	 * 
	 * @return rainProb
	 * 			  The probability of rain occuring in the simulation
	 */
	private double getRainProb() {
		switch (jComboBox2.getSelectedIndex()) {
		case 0:
			return 0;
		case 1:
			return 1.0;
		case 2:
			return 0.15;
		}
		return 0;
	}

	/** getTrafficLevel gets the selected traffic level from the GUI and returns the active percent of the population.
	 * 
	 * @return popPercent
	 *            Percent of the population that is active in the simulation.
	 */
	private double getTrafficLevel() {
		switch (jComboBox5.getSelectedIndex()) {
		case 0:
			return 0.85;
		case 1:
			return 0.6;
		case 2:
			return 0.3;
		}
		return 0;
	}

	
	/**
	 * getRoadmultipliers takes a neighborhood index from 0 to 3 and returns the corresponding multipliers for the roads it contains.
	 * 
	 * @param neighIdx
	 *            The index of the neighborhood
	 * @return roadMults
	 * 			  Multipliers for the roads in the neighborhood of index neighIdx
	 */
	private double[] getRoadMultipliers(int neighIdx) {
		double[] roadMults = new double[5];
		switch (neighIdx) {
		case 0:
			roadMults[0] = getMultFromAddlLanes(addlLanes[0]);
			roadMults[1] = 0;
			roadMults[2] = getMultFromAddlLanes(addlLanes[2]);
			roadMults[3] = getMultFromAddlLanes(addlLanes[1]);
			roadMults[4] = 0;
			break;
		case 1:
			roadMults[0] = getMultFromAddlLanes(addlLanes[4]);
			roadMults[1] = getMultFromAddlLanes(addlLanes[3]);
			roadMults[2] = 0;
			roadMults[3] = getMultFromAddlLanes(addlLanes[0]);
			roadMults[4] = 0;
			break;
		case 2:
			roadMults[0] = getMultFromAddlLanes(addlLanes[5]);
			roadMults[1] = 0;
			roadMults[2] = getMultFromAddlLanes(addlLanes[2]);
			roadMults[3] = getMultFromAddlLanes(addlLanes[3]);
			roadMults[4] = getMultFromAddlLanes(addlLanes[4]);
			break;
		case 3:
			roadMults[0] = getMultFromAddlLanes(addlLanes[1]);
			roadMults[1] = 0;
			roadMults[2] = 0;
			roadMults[3] = getMultFromAddlLanes(addlLanes[5]);
			roadMults[4] = 0;
			break;
		}
		return roadMults;
	}
	
	/**
	 * getMultFromAddlLanes takes the number of additional lanes and returns the corresponding lane multiplier
	 * 
	 * @param addlLanes
	 *            The number of lanes to add to the road
	 * @return laneMultiplier
	 * 			  The lane multiplier value
	 */
	private double getMultFromAddlLanes(int addlLanes) {
		switch (addlLanes) {
		case 0:
			return 1;
		case 1:
			return 1.33;
		case 2:
			return 1.5;
		case 3:
			return 1.66;
		}
		return 1;
	}

	
	/**
	 * ResetGUI resets the statistics and puts the GUI back into settings mode.<p>It takes no inputs and returns nothing, all results are shown on the GUI.
	 * 
	 */
	private void ResetGUI() {
		settingsActive = true;
		jTabbedPane1.setSelectedIndex(0);
		jList1.setSelectedIndex(0);
		/*
		 * jComboBox1.setSelectedIndex(0); jTextField3.setText("0");
		 * jTextField1.setText("12"); jTextField2.setText("30");
		 * jComboBox2.setSelectedIndex(0); jComboBox5.setSelectedIndex(0);
		 * jComboBox3.setSelectedIndex(0);
		 */
		showAccidents();
		for (int i = 0; i < numLanes.length; i++)
			updateRoadSettings(i);
		treeRoot.removeAllChildren();
		jTree1 = new javax.swing.JTree(treeRoot);
		jScrollPane3.setViewportView(jTree1);
		// jTree1.putClientProperty("JTree.lineStyle", "Angled");
		// treeRoot.removeAllChildren();
		// jTree1.setRootVisible(false);
	}
	
	/**
	 * GetStatistics gets the statistics resulting from the simulation and
	 * displays them on the GUI.
	 * <p>
	 * Its output is displayed on the GUI and not specifically returned.
	 */
	private void GetStatistics() {
		DefaultMutableTreeNode mainSystemNode = new DefaultMutableTreeNode(
				"System Statistics", true);
		treeRoot.add(mainSystemNode);

		mainSystemNode.add(new DefaultMutableTreeNode("Trains in System: "
				+ jTextField1.getText()));
		mainSystemNode.add(new DefaultMutableTreeNode("Simulation Length: "
				+ jTextField2.getText()));
		mainSystemNode.add(new DefaultMutableTreeNode("Traffic Level: "
				+ ((String) jComboBox5.getSelectedItem()) + " ("
				+ Integer.toString((int) (getTrafficLevel() * 100)) + "%)"));

		mainSystemNode
				.add(new DefaultMutableTreeNode(
						"Rained "
								+ ((jComboBox2.getSelectedIndex() == 2) ? ("(System Determined, "
										+ Integer
												.toString((int) (getRainProb() * 100)) + "% chance):")
										: "("
												+ Integer
														.toString((int) (getRainProb() * 100))
												+ "% chance): ")
								+ (mainSimulation.GetStatRainHistory() ? "Yes"
										: "No")));
		mainSystemNode.add(new DefaultMutableTreeNode("Total Accidents: "
				+ Integer.toString(mainSimulation.GetStatTotalNumAccidents())));

		DefaultMutableTreeNode mainRoadNode = new DefaultMutableTreeNode(
				"Road Statistics", true);
		treeRoot.add(mainRoadNode);
		for (int i = 0; i < 6; i++) {
			jList1.setSelectedIndex(i);
			DefaultMutableTreeNode roadNode = new DefaultMutableTreeNode(
					(String) jList1.getSelectedValue(), true);
			mainRoadNode.add(roadNode);
			for (int j = 0; j < 2; j++) {
				DefaultMutableTreeNode directionNode = new DefaultMutableTreeNode(
						streetDirections[i][j], true);
				roadNode.add(directionNode);
				directionNode.add(new DefaultMutableTreeNode("Avg trip speed: "
						+ Double.toString(mainSimulation
								.GetStatAvgSpeedPerRoute(
										lookupStartingNeigh[i][j],
										lookupRoadIdxs[i][j])) + " mph"));
				directionNode.add(new DefaultMutableTreeNode("Avg trip time: "
						+ Double.toString(mainSimulation
								.GetStatAverageTravelTimePerRoute(
										lookupStartingNeigh[i][j],
										lookupRoadIdxs[i][j])) + " minutes"));
				directionNode.add(new DefaultMutableTreeNode(
						"Avg Cars per Hour: "
								+ Double.toString(mainSimulation
										.GetStatAvgVehiclesPerHour(
												lookupStartingNeigh[i][j],
												lookupRoadIdxs[i][j]))));
				directionNode.add(new DefaultMutableTreeNode(
						"Number of Accidents: "
								+ Integer.toString(mainSimulation
										.GetStatNumAccidentsPerRoad(
												lookupStartingNeigh[i][j],
												lookupRoadIdxs[i][j]))));
				directionNode.add(new DefaultMutableTreeNode("Total Cars: "
						+ Integer.toString(mainSimulation
								.GetStatVehiclesPerRoute(
										lookupStartingNeigh[i][j],
										lookupRoadIdxs[i][j]))));
			}
		}
		int railNeighborhoodLookupTable[][] = new int[][] { new int[] { 0, 1 },
				new int[] { 3, 0 }, new int[] { 2, 1 }, new int[] { 3, 2 } };
		int railRouteIndexLookupTable[][] = new int[][] { new int[] { 5, 6 },
				new int[] { 5, 6 }, new int[] { 6, 5 }, new int[] { 6, 5 } };
		DefaultMutableTreeNode mainRailNode = new DefaultMutableTreeNode(
				"Rail Statistics", true);
		treeRoot.add(mainRailNode);
		for (int i = 0; i < 4; i++) {
			DefaultMutableTreeNode railNode = new DefaultMutableTreeNode(
					railNames[i], true);
			mainRailNode.add(railNode);
			for (int j = 5; j < 7; j++) {
				DefaultMutableTreeNode directionNode = new DefaultMutableTreeNode(
						railDirections[i][j - 5]);
				railNode.add(directionNode);
				int startingNeighborhood = railNeighborhoodLookupTable[i][j - 5];
				int routeIndex = railRouteIndexLookupTable[i][j - 5];
				directionNode.add(new DefaultMutableTreeNode("Avg trip speed: "
						+ Double.toString(mainSimulation
								.GetStatAvgSpeedPerRoute(startingNeighborhood,
										routeIndex)) + " mph"));
				directionNode.add(new DefaultMutableTreeNode("Avg trip time: "
						+ Double.toString(mainSimulation
								.GetStatAverageTravelTimePerRoute(
										startingNeighborhood, routeIndex))
						+ " minutes"));
				directionNode.add(new DefaultMutableTreeNode(
						"Avg Trains per Hour: "
								+ Double.toString(mainSimulation
										.GetStatAvgVehiclesPerHour(
												startingNeighborhood,
												routeIndex))));
				directionNode.add(new DefaultMutableTreeNode("Total Trains: "
						+ Integer.toString(mainSimulation
								.GetStatVehiclesPerRoute(startingNeighborhood,
										routeIndex))));
			}
		}
		settingsActive = false;
		jTabbedPane1.setSelectedIndex(1);
		// jTree1.setRootVisible(false);
		// jTree1.setModel(new DefaultTreeModel(treeRoot));
		for (int i = 0; i < jTree1.getRowCount(); i++) {
			jTree1.expandRow(i);
		}

	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton jButton1;

	private javax.swing.JButton jButton2;

	private javax.swing.JButton jButton3;

	private javax.swing.JButton jButton4;

	private javax.swing.JComboBox jComboBox1;

	private javax.swing.JComboBox jComboBox2;

	private javax.swing.JComboBox jComboBox3;

	private javax.swing.JComboBox jComboBox5;

	private javax.swing.JLabel jLabel1;

	private javax.swing.JLabel jLabel10;

	private javax.swing.JLabel jLabel11;

	private javax.swing.JLabel jLabel12;

	private javax.swing.JLabel jLabel13;

	private javax.swing.JLabel jLabel2;

	private javax.swing.JLabel jLabel3;

	private javax.swing.JLabel jLabel4;

	private javax.swing.JLabel jLabel5;

	private javax.swing.JLabel jLabel6;

	private javax.swing.JLabel jLabel7;

	private javax.swing.JLabel jLabel8;

	private javax.swing.JLabel jLabel9;

	private javax.swing.JList jList1;

	private javax.swing.JList jList2;

	private javax.swing.JPanel jPanel1;

	private javax.swing.JPanel jPanel2;

	private javax.swing.JPanel jPanel3;

	private javax.swing.JPanel jPanel4;

	private javax.swing.JPanel jPanel5;

	private javax.swing.JScrollPane jScrollPane1;

	private javax.swing.JScrollPane jScrollPane2;

	private javax.swing.JScrollPane jScrollPane3;

	private javax.swing.JTabbedPane jTabbedPane1;

	private javax.swing.JTextField jTextField1;

	private javax.swing.JTextField jTextField2;

	private javax.swing.JTextField jTextField3;

	private javax.swing.JTextPane jTextPaneA;

	private javax.swing.JTextPane jTextPaneB;

	private javax.swing.JTextPane jTextPaneC;

	private javax.swing.JTextPane jTextPaneD;

	private javax.swing.JTextPane jTextPaneE;

	private javax.swing.JTextPane jTextPaneF;

	private javax.swing.JTree jTree1;
	// End of variables declaration//GEN-END:variables

}
